package giermala.dominik.fotka.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "fotos")
public class Foto implements Serializable {

	private static final long serialVersionUID = -607436841517863301L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@ManyToOne
	private User fotkaUser;

	private String name;
	private Date date;
	private Integer averageNote;
	private Integer notesCounter;
	
	@Lob
	@Type(type = "org.hibernate.type.PrimitiveByteArrayBlobType")
	@Basic(fetch = FetchType.LAZY)
	private byte[] image;
	
	@OneToMany(mappedBy="foto", cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
	private final List<Note> notes = new LinkedList<Note>();
	
	@OneToMany(mappedBy="foto", cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
	private final List<Comment> comments = new LinkedList<Comment>();


	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Integer getAverageNote() {
		return averageNote;
	}

	public void setAverageNote(Integer averageNote) {
		this.averageNote = averageNote;
	}

	public Integer getNotesCounter() {
		return notesCounter;
	}

	public void setNotesCounter(Integer notesCounter) {
		this.notesCounter = notesCounter;
	}

	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	public User getFotkaUser() {
		return fotkaUser;
	}

	public void setFotkaUser(User fotkaUser) {
		this.fotkaUser = fotkaUser;
	}

	public List<Note> getNotes() {
		return notes;
	}

	public List<Comment> getComments() {
		return comments;
	}

	@Override
	public String toString() {
		return "id: " + Long.toString(id) + ", name: " + name 
				+ ", date: " + date + ", averageNote: "
				+ Integer.toString(averageNote) + ", notesCounter: "
				+ Integer.toString(notesCounter);
	}
}
